home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / vpwnd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-16  |  5.0 KB  |  216 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // VPWnd.cpp : implementation file
  12. // TurboCAD SDK: new class implementation
  13.  
  14. #include "stdafx.h"
  15. #include "LTSample.h"
  16. #include "VPWnd.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CViewWnd
  26. // TurboCAD SDK: class created to manage view on dialog box
  27.  
  28. CViewWnd::CViewWnd() :
  29.     m_pView(NULL),
  30.     m_bStartSelect(FALSE),
  31.     m_pIDrawing(NULL)
  32. {
  33.     m_varTopLevel.vt = VT_BOOL;
  34.     m_varInvisible.vt = VT_BOOL;
  35.     m_varSegments.vt = VT_BOOL;
  36.     m_varArcs.vt = VT_BOOL;
  37.     m_varTexts.vt = VT_BOOL;
  38.     m_varBlocks.vt = VT_BOOL;
  39.  
  40.     m_varTopLevel.boolVal = FALSE;
  41.     m_varInvisible.boolVal = FALSE;
  42.     m_varSegments.boolVal = TRUE;
  43.     m_varArcs.boolVal = TRUE;
  44.     m_varTexts.boolVal = TRUE;
  45.     m_varBlocks.boolVal = TRUE;
  46. }
  47.  
  48. CViewWnd::~CViewWnd()
  49. {
  50.     SetView(NULL);
  51. }
  52.  
  53.  
  54. BEGIN_MESSAGE_MAP(CViewWnd, CWnd)
  55.     //{{AFX_MSG_MAP(CViewWnd)
  56.     ON_WM_PAINT()
  57.     ON_WM_LBUTTONDOWN()
  58.     ON_WM_ERASEBKGND()
  59.     //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61.  
  62. // TurboCAD SDK: set the view, if one already exists, delete and release it
  63. //               before assigning the new one.
  64. void CViewWnd::SetView(View* pView)
  65. {
  66.     if (m_pView != NULL)
  67.     {
  68.         // Delete view object
  69.         m_pView->Delete();
  70.  
  71.         // Decrement reference count
  72.         m_pView->Release();
  73.         m_pView = NULL;
  74.         if (m_pIDrawing != NULL)
  75.         {
  76.             m_pIDrawing->Release();
  77.             m_pIDrawing = NULL;
  78.         }
  79.     }
  80.  
  81.     if (pView == NULL)
  82.         return;
  83.  
  84.     m_pView = pView;
  85.  
  86.     // Increment reference count
  87.     m_pView->AddRef();
  88.  
  89.     m_pView->put_Update(FALSE);
  90.     // Map window to view
  91.     m_pView->put_HWND((long)m_hWnd);
  92.  
  93.     // Keep a reference to the drawing
  94.     m_pView->get_Drawing(&m_pIDrawing);
  95.  
  96.     // zoom to drawing extents and invalidate the window
  97.     ZoomAndInvalidate();
  98. }
  99.  
  100. BOOL CViewWnd::SetSelectMode()
  101. {
  102.     m_bStartSelect = ~m_bStartSelect;
  103.     return m_bStartSelect;
  104. }
  105.  
  106. IDrawing* CViewWnd::GetDrawing()
  107. {
  108.     if (m_pIDrawing != NULL)
  109.         m_pIDrawing->AddRef();
  110.     return m_pIDrawing;
  111. }
  112.  
  113. Graphics* CViewWnd::GetGraphics()
  114. {
  115.     Graphics* pGraphics = NULL;
  116.     if (m_pIDrawing != NULL)
  117.         m_pIDrawing->get_Graphics(&pGraphics);
  118.     return pGraphics;
  119. }
  120.  
  121. // TurboCAD SDK: zoom to drawing extents and invalidate the window
  122. void CViewWnd::ZoomAndInvalidate()
  123. {
  124.     // No view, exit
  125.     if (m_pView == NULL)
  126.         return;
  127.  
  128.     // Zoom to extents
  129.     m_pView->ZoomToExtents();
  130.  
  131.     // Invalidate window to force redraw
  132.     Invalidate();
  133. }
  134.  
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CViewWnd message handlers
  137.  
  138. // TurboCAD SDK: override OnPaint to refresh the view
  139. void CViewWnd::OnPaint() 
  140. {
  141.     CPaintDC dc(this); // device context for painting
  142.     
  143.     if (m_pView == NULL)
  144.         return;
  145.  
  146.     // Force redraw of view window
  147.     m_pView->Refresh();
  148. }
  149.  
  150. // TurboCAD SDK: override OnEraseBkgnd to reset the drawing area
  151. BOOL CViewWnd::OnEraseBkgnd(CDC* pDC) 
  152. {
  153.     CRect rect;
  154.     GetClientRect(rect);
  155.     pDC->FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));
  156.     return TRUE;
  157. }
  158.  
  159. void CViewWnd::OnLButtonDown(UINT nFlags, CPoint point) 
  160. {
  161.     if (m_bStartSelect)
  162.     {
  163.         Selection *pSel = NULL;
  164.         HRESULT hRes = m_pIDrawing->get_Selection(&pSel);
  165.         if (SUCCEEDED(hRes))
  166.         {
  167.             pSel->Unselect();
  168.             pSel->Release();
  169.         }
  170.  
  171.         double dblX, dblY;
  172.         m_pView->ScreenToView(point.x,point.y, &dblX,&dblY);
  173.  
  174.         COleVariant varAperture((const double&)0.1);
  175.         PickResult *pPickRes = NULL;
  176.  
  177.         hRes = m_pView->PickPoint(dblX, dblY,
  178.                                    &varAperture,
  179.                                    &m_varTopLevel,
  180.                                    &m_varArcs,
  181.                                    &m_varTexts,
  182.                                    &m_varSegments,
  183.                                    &m_varBlocks,
  184.                                    &m_varInvisible,
  185.                                    &pPickRes);
  186.         if (SUCCEEDED(hRes))
  187.         {
  188.             PickEntry *pPickEntry = NULL;
  189.             COleVariant varIndex((long)0);
  190.             hRes = pPickRes->get_Item(&varIndex,&pPickEntry);
  191.             if (SUCCEEDED(hRes))
  192.             {
  193.                 IGraphic *pIGr = NULL;
  194.                 hRes = pPickEntry->get_Graphic(&pIGr);
  195.                 if (SUCCEEDED(hRes))
  196.                 {
  197.                     hRes = pIGr->Select();
  198.                     if (SUCCEEDED(hRes))
  199.                     {
  200.                         AfxMessageBox(IDS_SYMBOLSELECTED);
  201.                     }
  202.                     else
  203.                         AfxMessageBox(IDS_CANNOTSELECTGRAPHIC);
  204.                     pIGr->Release();
  205.                 }
  206.                 pPickEntry->Release();
  207.             }
  208.             else
  209.                 AfxMessageBox(IDS_CANNOTGETPICKENTRY);
  210.             pPickRes->Release();
  211.         }
  212.         GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(IDC_SELECTSYMBOL, BN_CLICKED), 0);
  213.     }
  214.     CWnd::OnLButtonDown(nFlags, point);
  215. }
  216.